package fjut.acm.coding.service.Impl;

import fjut.acm.coding.entity.UserContestProblemSloved;
import fjut.acm.coding.mapper.UserContestProblemSlovedMapper;
import fjut.acm.coding.service.UserContestProblemSlovedService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserContestProblemSlovedServiceImpl implements UserContestProblemSlovedService {

    @Resource
    UserContestProblemSlovedMapper userContestProblemSlovedMapper;

    @Override
    public UserContestProblemSloved selectOnlyOne(String username, Integer contestId, Integer problemId) {
        Example example = new Example(UserContestProblemSloved.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("contestId",contestId)
                .andEqualTo("username",username)
                .andEqualTo("problemId",problemId);
        return userContestProblemSlovedMapper.selectOneByExample(example);
    }

    @Override
    public Integer addOneUserContestProblemSloved(UserContestProblemSloved userContestProblemSloved) {
        return userContestProblemSlovedMapper.insert(userContestProblemSloved);
    }

    @Override
    public List<UserContestProblemSloved> selectByContestId(Integer contestId) {
        Example example = new Example(UserContestProblemSloved.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("contestId",contestId);
        return userContestProblemSlovedMapper.selectByExample(example);
    }

    @Override
    public Integer updateWrong(UserContestProblemSloved userContestProblemSloved) {
        return userContestProblemSlovedMapper.updateByPrimaryKey(userContestProblemSloved);
    }

    @Override
    public Integer updateSloved(UserContestProblemSloved userContestProblemSloved) {
        return userContestProblemSlovedMapper.updateByPrimaryKey(userContestProblemSloved);
    }
}
